package com.bc.web.controller.admin;

import com.bc.web.interceptors.AuthInterceptor;
import com.bc.web.model.AdminRole;
import com.fs.common.extend.FSController;
import com.fs.common.util.FSDate;
import com.jfinal.plugin.activerecord.Page;

public class AdminRoleController extends FSController{
	
	public void search(){
		Page<AdminRole> pageResult = AdminRole.dao.search(super.getSearchCondition());
		setPageResultToRequest("items", pageResult);
		render("system/adminRoleList.html");
	}
	
	public void addPage(){
		render("system/adminRoleAdd.html");
	}
	
	public void add(){
		AdminRole role = getModel(AdminRole.class);
		role.setUpdateDateTime(FSDate.getDateTime());
		role.save();
		renderSuccess();
	}
	
	public void updatePage(){
		setAttr("item", AdminRole.dao.findById(getPara("id")));
		render("system/adminRoleUpdate.html");
	}
	
	public void update(){
		AdminRole role = getModel(AdminRole.class);
		role.setUpdateDateTime(FSDate.getDateTime());
		role.update();
		renderSuccess();
	}
	
	public void delete() {
		AdminRole.dao.deleteById(getPara("id"));
		renderSuccess(false);
	}
	
	public void alloctSourcePage(){
		AdminRole role = AdminRole.dao.findById(getParaToInt("id"));
		setAttr("adminRole", role);
		setAttr("sourceList", AuthInterceptor.getSidebar_admin_zh_CN());
		render("system/adminRoleAlloctSource.html");
	}
	
	public void saveAlloctSource(){
		String[] sourceGroup = getParaValues("sourceGroup");
		String[] sourceUrl = getParaValues("sourceUrl");
		AdminRole role = getModel(AdminRole.class);
		String group = "";
		for (String tmp : sourceGroup) {
			group += tmp + ",";
		}
		String url = "";
		for (String tmp : sourceUrl) {
			url += tmp + ",";
		}
		role.setSourceGroup(group);
		role.setSourceUrl(url);
		role.setUpdateDateTime(FSDate.getDateTime());
		role.update();
		renderSuccess(true);
	}
	
}
